#include<sys/types.h>
#include<sys/wait.h>
#include<stdio.h>
#include<stdlib.h>
#include<errno.h>
int main()
{
    pid_t pid = fork();

    if(pid == -1)
    {
        perror("fork");
        exit(1);
    }

    if(pid == 0){
        printf("%d\n",getpid());
        sleep(20);
        exit(10);
    }
    else{
        int st;
        int ret = wait(&st);
        //0x7F转成二进制1111 111，因为子进程正常退出st的0-7比特位都是0
        //我们&0x7F是为了验证子进程是否正常退出
        if(ret > 0 && (st & 0x7F)==0){
            printf("child exit code:%d\n",(st>>8)&0xFF);
        }
        else if(ret > 0)
        {
            printf("sig code: %d\n",st&0x7f);
        }
    }
    return 0;
}